import { createStore } from 'vuex'
import city from './city'
import createPersistedState from "vuex-persistedstate";
import { CinemaDataAPI } from '@/api/index.js'
const store = createStore({
  // vuex数据持久化
  plugins: [createPersistedState({
    storage:window.sessionStorage,
    reducer(state){
      return {
        name:state.name,
        status:state.status,
        isShowBack:state.isShowBack,
        title:state.title,
      }
    }
  })],
  state: {
    isShowBack:false,
    name:'',
    status:0,
    CinemaList:[],
    title:'电影',
    // showDate:'',
    // filmId:'',
    // cinemaId:''
  },
  getters: {
  },
  mutations: {
    getIsShowBack(state , val){
    
      state.isShowBack=val[0]
      state.title=val[1]
    },
    MovieName(state , val){
      state.name = val
    },
    Modification(state , val){
      state.status = val
    },
    UPDATE_SOCKET_INFO(state,val){
      state.CinemaList = val
    },
    // SEAT_UPDATE_INFO(state,val){
    //   state.cinemaId=val[0]
    //   state.showDate=val[1]
    //   state.filmId =val[2]
    // },
  },
  actions: {
    async GET_SOCKET_INFO ({commit}){
      const { data:res } = await CinemaDataAPI({id:store.state.city.cityId})
      commit('UPDATE_SOCKET_INFO',res.data.cinemas)
    },

  },
  modules: {
    city
  }
})
export default store